package cn.dapeng.pool;

import cn.dapeng.util.SleepingUtil;

import java.util.concurrent.*;

public class Test {

//    public static ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor();
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(1);

        String str = "abcdefghijklmnopqrstuvwsyz";

        char[] chars = str.toCharArray();

        for (char c : chars) {
            int activeCount = ((ThreadPoolExecutor) executor).getActiveCount();

            if(activeCount > 1) {
                System.out.println(" over ");
                return;
            }
            ;
            executor.submit(() -> {
               // SleepingUtil.sleep(ThreadLocalRandom.current().nextInt(10), TimeUnit.SECONDS);
                System.out.println("current task count => " + activeCount);
                System.out.println(Thread.currentThread().getName() + " => " + c);
            });
        };

        executor.shutdown();
    }
}
